/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package encomienda.controlador;

import com.opensymphony.xwork2.ActionSupport;
import encomienda.modelo.Cliente;
import encomienda.servicio.ClienteServicio;
import encomienda.servicio.ClienteServicioImpl;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
/**
 *
 * @author JUAN
 */
@Action(value="ClienteControl",results={
@Result(name="ClienteForm", location="/Encomienda/Modulos/Cliente/clienteForm.jsp"),
@Result(name="actulizarForm", location="/Encomienda/Modulos/Cliente/clienteFormActulizar.jsp"),
@Result(name="formBuscar", location="/Encomienda/Modulos/Cliente/clienteBuscar.jsp"),
@Result(name="reporte", location="/Encomienda/Modulos/Cliente/clienteLista.jsp")
})
public class ClienteControl extends ActionSupport{
    Cliente to;
    String msg;
    ClienteServicio clienteServ=new ClienteServicioImpl();
    private Log logger=LogFactory.getLog(this.getClass());
    Map<String, Object> modelo=new HashMap<String, Object>();
    
    /*--------------------------------------------------------------------------------- */
    
    public String reportCliente() throws Exception{
        try {
            modelo.put("msgA", "JUAN ROBERTO QUISPE ALCCA");
            modelo.put("clienteLista", clienteServ.reportarCliente());
        } catch (Exception e) { return "error"; }
        return "reporte";
    }
    
    /*--------------------------------------------------------------------------------- */

    public String insertCliente() throws Exception{
    return "ClienteForm";
    }
 
    public String guardarCliente() throws Exception{
    try {
        clienteServ.insertarCliente(to);  
        //modelo.put("msgA", "Accion Realizada Correctamente");    
    } catch (Exception e){return "error"; }
    return reportCliente();
}
    /*--------------------------------------------------------------------------------- */
    
    public String eliminarCliente() throws Exception{
    try {
        clienteServ.elimminarCliente(to.getIdCliente());
    } catch (Exception e) { return "error"; }
    return reportCliente();      
}
 
    /*--------------------------------------------------------------------------------- */
        
    public String clienteFormActulizar() throws Exception{
    try {
        to=clienteServ.reportaClienteId(to.getIdCliente());
        setMsg("El item "+to.getNombre()+" is finded" );
    } catch (Exception e) {addActionError("ClienteAction.clienteActualizar "+e.getMessage()); return "error";
    }return "actulizarForm";
}
    public String actulizarTrabajador() throws Exception{
    try {
        clienteServ.actualizarCliente(to);
    } catch (Exception e) {
        return "error";
    }
    return reportCliente();
}
    /*--------------------------------------------------------------------------------- */
    public String clienteFormBus() throws Exception{
    return "formBuscar";
}

public String buscarTrabajador() throws Exception{
    logger.info("Holasss:  "+to.getNombre());
    try {
      modelo.put("trabajadorLista2", clienteServ.reportarClienteCliente(to.getNombre()));       
    } catch (Exception e) {
        return "error";
    }
    return "formBuscar";
}
    /*--------------------------------------------------------------------------------- */

    public Log getLogger() {
        return logger;
    }

    public void setLogger(Log logger) {
        this.logger = logger;
    }

    public Map<String, Object> getModelo() {
        return modelo;
    }

    public void setModelo(Map<String, Object> modelo) {
        this.modelo = modelo;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Cliente getTo() {
        return to;
    }

    public void setTo(Cliente to) {
        this.to = to;
    }




}


